Skip to content

Correct implementation of gcc specific internal functions #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

kibergus
Copy link

This patch add correct implementation for:

int __cxa_guard_acquire(__guard *);
void __cxa_guard_release (__guard *);
void __cxa_guard_abort (__guard *); 
void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));

Current implementations in arduino are just stubs that can lead to undefined behavior if one of that functions is used. __cxa_guard_acquire, __cxa_guard_release and __cxa_guard_abort are needed for thread safe initialization of static variables (in case if they can't be initialized at compile time). If you don't need thread safety just turn it of with -fno-threadsafe-statics. Buf if you provide it, provide correct implementation, not a stub.

__cxa_pure_virtual and __cxa_deleted_virtual are called if thing went really wrong and they must not return. They must terminate the program because it is already broken.

@matthijskooijman
Copy link
Collaborator

These implementations look good to me. Unlike the previous stubs, they actually work and, like kibergus says, if you don't want the extra overhead (which only occurs when declaring static variables with non-constant initializers) you can compile with -fno-threadsafe-statics.

@kibergus, could you confirm that you actually wrote this code and add a copyright header and license to this file?

@kibergus
Copy link
Author

kibergus commented Feb 6, 2014

Yes, I've written them on my own and you can use this code as you want. Anyway, this is a sort of trivial code: you can't rewrite it in different stile if you want the same behaviour.
For __cxa_pure_virtual and __cxa_deleted_virtual may be I've taken trivial realization from gcc which just calls std::terminate. That realization is used when you disable all goodies like printing of occured error and place in code where it has occured.

Using -fno-threadsafe-statics by default may be a good choice for arduino IDE. If you do so, you can even drop definition of __cxa_guard_acquire, __cxa_guard_release and __cxa_guard_abort.

@ffissore ffissore added the New label Feb 27, 2014
cmaglie added a commit to cmaglie/Arduino that referenced this pull request Sep 6, 2014
The following empty stubs has been replaced by the gcc
flag -fno-threadsafe-static:

  int __cxa_guard_acquire(__guard *);
  void __cxa_guard_release (__guard *);
  void __cxa_guard_abort (__guard *);

The following empty stubs has been moved into their specific
module abi.cpp:

  void __cxa_pure_virtual(void) __attribute ((noreturn));
  void __cxa_deleted_virtual(void) __attribute ((noreturn));

Fix arduino#107
@cmaglie cmaglie added 1.5 and removed New labels Sep 6, 2014
@cmaglie
Copy link
Member

cmaglie commented Sep 8, 2014

Solved with #2284. Thank you.

@cmaglie cmaglie closed this Sep 8, 2014
tbowmo pushed a commit to tbowmo/Arduino that referenced this pull request Jul 14, 2016
added dualoptiboot to mysensors hardware profile
ollie1400 pushed a commit to ollie1400/Arduino that referenced this pull request May 2, 2022
The following empty stubs has been replaced by the gcc
flag -fno-threadsafe-static:

  int __cxa_guard_acquire(__guard *);
  void __cxa_guard_release (__guard *);
  void __cxa_guard_abort (__guard *);

The following empty stubs has been moved into their specific
module abi.cpp:

  void __cxa_pure_virtual(void) __attribute ((noreturn));
  void __cxa_deleted_virtual(void) __attribute ((noreturn));

Fix arduino#107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Related to the code for the standard Arduino API feature request A request to make an enhancement (not a bug fix)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants